/**
 * @overview 计算多边形质心
 * @author dengqiang
 * @description 引用Turf 计算平滑 bezierSpline
 * @update  2022.04.14
 */
class GCalculateCenPos {
  constructor() {
    window.GCalculateCenPosArray = []
  }

  /**
   * @description 计算多边形质心
   * @param option posArr:[[118,23,15],[118,23,15],[118,23,15]]
   */
  calculateCenPos(posArr) {
    const posList = []
    posArr.forEach((ele) => {
      posList.push([ele[0], ele[1]])
    })
    posList.push([posArr[0][0], posArr[0][1]])
    const polygon = turf.polygon([posList])
    const center = turf.centerOfMass(polygon)
    const cenPos = center.geometry.coordinates //只有经纬度，需要手动添加高度
    cenPos.push(posArr[0][2])
    window.GCalculateCenPosArray = cenPos
    return cenPos
  }
}

export default GCalculateCenPos
